package com.smsc.headend.task.engine.service.push.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smsc.headend.module.protocol.cosem.bo.CosemData;
import com.smsc.headend.module.push.entity.ConfigNotifyTypeParam;
import com.smsc.headend.task.engine.mapper.push.ConfigNotifyTypeParamMapper;
import com.smsc.headend.task.engine.service.push.ConfigNotifyTypeParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (业务实现)
 *
 * @author wjh
 * @date 2022/6/17 10:46.
 */
@Service
@Slf4j
public class ConfigNotifyTypeParamServiceImpl extends ServiceImpl<ConfigNotifyTypeParamMapper, ConfigNotifyTypeParam> implements ConfigNotifyTypeParamService {
    @Override
    public List<ConfigNotifyTypeParam> getListByNotifyTypeId(Long notifyTypeId) {
        return baseMapper.selectList(Wrappers
                .<ConfigNotifyTypeParam>lambdaQuery()
                .eq(ConfigNotifyTypeParam::getNotifyTypeId, notifyTypeId));
    }

    @Override
    public CosemData getCosemDataByIndex(CosemData cosemData, String indexStr) {
        if (StrUtil.isEmpty(indexStr)) {
            return null;
        }
        String[] indexList = indexStr.split(",");
        CosemData child = cosemData;
        for (String index1 : indexList) {
            int id = Integer.valueOf(index1);
            if (null != child) {
                child = child.getChildAt(id);
            } else {
                return null;
            }
        }
        return child;
    }
}
